﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace FCS.Communication
{
    /// <summary>
    /// Provides helper methods that ensure all logging is done in the correct log file
    /// </summary>
    public class EventLogWriter
    {
        const string _sLog = "Enlight";
        string _sSource;

        /// <summary>
        /// Sets up the source of the event logging. This is usually the name of the project
        /// that is writting to the log. E.g. The kiosk client passes in the string "Kiosk" as 
        /// the source. 
        /// </summary>
        /// <param name="source"></param>
        public EventLogWriter(string source)
        {
            _sSource = source;
        }

        /// <summary>
        /// Writes the message with status to the Enlight event log
        /// </summary>
        /// <param name="status"></param>
        /// <param name="message"></param>
        public void WriteToLog(EventLogEntryType status, string message)
        {
            if (!EventLog.SourceExists(_sSource))
                EventLog.CreateEventSource(_sSource, _sLog);

            EventLog.WriteEntry(_sSource, message, status);
        }
    }
}
